<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/20
 * Time: 15:21
 */

namespace api\controllers;

use api\models\ApiLoginForm;
use yii\rest\ActiveController;

class AuthController extends ActiveController
{
    public $modelClass = 'api\models\Adminuser';

    public function actionLogin()
    {
        $model = new ApiLoginForm();
        $model->username = $_POST['username'];
        $model->password = $_POST['password'];
        //$model->load(\Yii::$app->getRequest()->getBodyParams(), '');
        if ($token = $model->login()) {
            return ['access_token' => $token];
        } else {
            $model->validate();
            return $model;
        }
    }
}